//
//  main.c
//  electronic_scale
//
//  Created by fukai on 2019/4.
//  Copyright © 2019 Cyber SmartCar Lab. All rights reserved.
//

#include "../bsp/board_driver/tick_timer.h" 
#include "../bsp/board_driver/key.h"
#include "../bsp/board_driver/beep.h"
#include "../bsp/board_driver/oled.h"
#include "../bsp/board_driver/hx711.h"
#include "./info_proc.h"
#include "./timer_interrupt.h"
#include "./user_interface.h"

//主循环状态机
typedef enum
{
	GET_INFO = 0,
	PROC_INFO,
	SHOW_INFO,
}MainStatusType;
MainStatusType MainStatus = GET_INFO;


//硬件初始化
void BoardInit(void)
{
	DelayInit();	//滴答定时器初始化
	OledInit();
	HX711Init(); 
	KeyInit();
	BeepInit();
	Tim2IntInit(29,7199);	//3ms一次中断  72000000/7200=10kHZ  
}

int main(void)
{
	BoardInit();
	while(1)
	{
		switch(MainStatus)
		{
			case GET_INFO:
				ScaleInfo.default_data = HX711Read();
				MainStatus = PROC_INFO;
				break;
			
			case PROC_INFO:
				ProcData();
				MainStatus = SHOW_INFO;
				break;
			
			case SHOW_INFO:
				UserInterface();
				MainStatus = GET_INFO;
				break;
		}
	}
}


